package com.lvxingli.generateannotation.action.intention;

import com.lvxingli.generateannotation.action.intention.base.AbstractUniversalGenerateIntentionAction;
import com.lvxingli.generateannotation.constants.ActionEnum;
import com.lvxingli.generateannotation.constants.IntentionFamilyEnum;
import com.lvxingli.generateannotation.factory.CommandCommandTypeProcessorFactory;
import com.lvxingli.generateannotation.pojo.SelectWrapper;
import com.lvxingli.generateannotation.pojo.WriteCommand;
import com.lvxingli.generateannotation.pojo.WriteContext;
import com.lvxingli.generateannotation.util.DecisionUtils;
import com.lvxingli.generateannotation.util.builder.WriteContextIntentionBuilder;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;

/**
 * 在当前文件中填充所有注解：Swagger注解、Protostuff注解
 *
 * @author lvxingli
 */
@Slf4j
public class PopulateAnnotationForFileIntentionAction extends AbstractUniversalGenerateIntentionAction {

    @Override
    protected boolean calcIsAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) {
        SelectWrapper selectWrapper = DecisionUtils.parseSelectWrapper(project, editor, element);
        return !selectWrapper.isSelected();
    }

    @Override
    protected void doInvoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) {
        WriteContext writeContext = WriteContextIntentionBuilder.create(project, editor, element);
        CommandCommandTypeProcessorFactory.decide(writeContext, WriteCommand.Command.POPULATE_WRITE_SWAGGER).writeFile();
        CommandCommandTypeProcessorFactory.decide(writeContext, WriteCommand.Command.POPULATE_WRITE_TAG).writeFile();
    }

    @Override
    protected IntentionFamilyEnum fetchIntentionFamilyEnum() {
        return IntentionFamilyEnum.GENERATE_ANNOTATION;
    }

    @Override
    protected ActionEnum fetchActionEnum() {
        return ActionEnum.POPULATE_MISSING_ANNOTATION_FOR_FILE;
    }
}
